import com.ruoyi.system.domain.CoursePlan;
import com.ruoyi.system.utils.Upload;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Slf4j
public class Test {
    public static void s1() throws IOException {


        FileInputStream file = new FileInputStream("D:\\ruoyi\\school\\ruoyi-ui\\public\\时间表模板.xlsx");

        XSSFWorkbook wb1 = new XSSFWorkbook(file);

        String[][] result = new String[0][];
        try {
            // 获取Excel表文件里的数据
            //第二个参数为从Excel文件里第几行开始读
            result = Upload.getData(wb1, 0);
            for (int i = 0; i < result.length; i++) {
                for (int j = 0; j < result[i].length - 1; j++) {
                    log.info("result[i][j] = " + "result[" + i + "][" + j + "] = " + result[i][j]);
                }
            }
            int len = result.length;
            log.info("result.length = " + len);
            if (len < 0) {
                return;
            }

            file.close();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            file.close();
        }
    }

    public static CoursePlan s2() throws IOException {

        CoursePlan coursePlan = new CoursePlan();
        FileInputStream file = new FileInputStream("/Users/timmy/work/school/ruoyi-ui/public/课程表模板.xlsx");

        XSSFWorkbook wb1 = new XSSFWorkbook(file);

        String[][] result = new String[0][];
        try {
            // 获取Excel表文件里的数据
            //第二个参数为从Excel文件里第几行开始读
            result = Upload.getFullData(wb1, 0);

            for (int i = 0; i < result.length; i++) {
                for (int j = 0; j < result[i].length - 1; j++) {
                    log.info("result[i][j] = " + "result[" + i + "][" + j + "] = " + result[i][j]);
                }
                if (i == 0) {
                    String yq = result[i][0];
                    String pattern = "([1-9]\\d*)|([零|一|二|三|四|五|六|七|八|九|十]+)";

                    Pattern r = Pattern.compile(pattern);
                    Matcher m = r.matcher(yq);
                    int f = 0;
                    while (m.find()) {
                        switch (f) {
                            case 0:
                                coursePlan.setYear(m.group().trim());
                                break;
                            case 1:
                                coursePlan.setQuarter(m.group().trim());
                                break;
                            case 2:
                                coursePlan.setGrade(m.group().trim() + "年级");
                                break;
                            case 3:
                                coursePlan.setClazz(m.group().trim() + "班");
                                break;
                            default:
                                break;
                        }
                        f++;
                    }
                    System.out.println(f);
                }
                if (i > 1) {

                    coursePlan.getPeriod().add(result[i][0]);
                    coursePlan.getId().add(result[i][1]);
                    coursePlan.getMonday().add(result[i][2]);
                    coursePlan.getTuesday().add(result[i][3]);
                    coursePlan.getWednesday().add(result[i][4]);
                    coursePlan.getThursday().add(result[i][5]);
                    coursePlan.getFriday().add(result[i][6]);
                    coursePlan.getSaturday().add(result[i][7]);
                    coursePlan.getSunday().add(result[i][8]);
                }
            }
            file.close();

        } catch (Exception e) {
            log.error("导入失败", e);
        } finally {
            file.close();
        }
        return coursePlan;
    }

    public static void main(String[] args) throws IOException {
//        CoursePlan coursePlan = s2();
//        System.out.println(coursePlan);

        String yq = "  2024  学年度春季作息时间表";
//        String pattern = "([1-9]\\d*)|([零|一|二|三|四|五|六|七|八|九|十]+)";
        String pattern = "([1-9]\\d*)|([零|一|二|三|四|五|六|七|八|九|十]+)|([春|夏|秋|冬]+)";
        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(yq);

        while (m.find()) {
            System.out.println(m.group());
        }
    }
}
